package com.wl.thread.demo03;

/**
 * 观察线程状态
 */
public class TestThreadState{

    public static void main(String[] args) {
        Thread thread = new Thread(()->{
            for (int i = 0; i < 5; i++) {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            System.out.println("休眠结束");
        });

        Thread.State state = thread.getState();
        //NEW
        System.out.println(state);

        //启动线程
        thread.start();
        state = thread.getState();
        //RUNNABLE
        System.out.println(state);

        while (state != Thread.State.TERMINATED){
            try {
                Thread.sleep(100);
                state = thread.getState();
                System.out.println(state);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
